package com.example.myapplication2003;

import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.ViewPager;

import android.os.Bundle;
import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.example.myapplication2003.adapter.ViewPagerAdapter;

public class ViewPagerActivity extends AppCompatActivity {

    int[] images = new int[] {
            R.drawable.banner1,
            R.drawable.banner2,
            R.drawable.banner3,
            R.drawable.banner4,
            R.drawable.banner5,
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_view_pager);

        // 定义adapter
        ViewPagerAdapter viewPagerAdapter =
                new ViewPagerAdapter(this, images);

        // 关联ViewPager
        ViewPager viewPager = findViewById(R.id.view_pager);
        viewPager.setAdapter(viewPagerAdapter);   // 关联

        // 渲染指示器圆点
        RadioGroup radioGroup = findViewById(R.id.radio_group);
        for(int i=0; i<images.length; i++) {
            // 动态生成RadioButton组件，添加到RadioGroup组件内部
            RadioButton radioButton = new RadioButton(this);
            radioGroup.addView(radioButton);
        }
    }
}